package com.boot.security.server.dict.controller;

import com.boot.security.server.common.Result;
import com.boot.security.server.dict.model.DataDictDetails;
import com.boot.security.server.dict.model.LayUiModel;
import com.boot.security.server.dict.param.DictDetailsParam;
import com.boot.security.server.dict.service.IDictDetailsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 字典详情
 * @author Administrator
 */
@SuppressWarnings("ALL")
@RestController
@RequestMapping("/dictDetails")
public class DataDictDetailsController {

    @Autowired
    private IDictDetailsService detailsService;

    @PostMapping("/findByDictId/{dictId}")
    @ApiOperation(value = "查询数据字典详情")
    @ResponseBody
    public LayUiModel findByDictId (@PathVariable Integer dictId, HttpServletRequest request) {
        DictDetailsParam param = new DictDetailsParam();
        param.setDictId(dictId);
        return detailsService.findByDictId(param, request);
    }

    @GetMapping("/findById/{id}")
    @ApiOperation(value = "查询数据字典详情-编辑")
    @ResponseBody
    public LayUiModel findById (@PathVariable Integer id) {
        return detailsService.findById(id);
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加数据字典详情")
    public Result addDetails (@RequestBody DataDictDetails details) {
        return detailsService.add(details);
    }

    @PostMapping("/update")
    @ApiOperation(value = "数据字典详情-编辑")
    @ResponseBody
    public Result updateDict (@RequestBody DataDictDetails details) {
        return detailsService.update(details);
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除数据字典详情")
    public Result delDict (@PathVariable Integer id) {
        return detailsService.delete(id);
    }

    @GetMapping("/findMaxDataKeyByDictId/{dictId}")
    @ApiOperation(value = "查询数据字典详情-最大key")
    @ResponseBody
    public LayUiModel findMaxDataKeyByDictId (@PathVariable Integer dictId) {
        return detailsService.findMaxDataKeyByDictId(dictId);
    }
}
